using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using SqlMiM.ViewModel;
using SqlMiM.Common;
using System.Linq;
using SqlMiM.Common.Converters;


namespace SqlMiM.Views
{
    /// <summary>
    /// Interaction logic for DocumentsView.xaml
    /// </summary>

    public partial class DocumentsView : System.Windows.Controls.UserControl
    {


        public PluginViewModel ActivePlugin
        {
            get { return (PluginViewModel)GetValue(ActivePluginProperty); }
            set { SetValue(ActivePluginProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SelectedPlugin.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ActivePluginProperty =
            DependencyProperty.Register("ActivePlugin", typeof(PluginViewModel), typeof(DocumentsView), new UIPropertyMetadata(null));




        public ObservableCollection<PluginViewModel> CurrentPlugins
        {
            get { return (ObservableCollection<PluginViewModel>)GetValue(CurrentPluginsProperty); }
            set { SetValue(CurrentPluginsProperty, value); }
        }

        // Using a DependencyProperty as the backing store for LoadedPlugins.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CurrentPluginsProperty =
            DependencyProperty.Register("CurrentPlugins", typeof(ObservableCollection<PluginViewModel>), typeof(DocumentsView), new UIPropertyMetadata(null));





        public DocumentsView()
        {
            InitializeComponent();

           // Context.Current.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Current_PropertyChanged);

            Binding b = new Binding();
            b.Source = PluginContext.Current;
            b.Path = new PropertyPath("CurrentPlugins");
            b.Mode = BindingMode.TwoWay;
            this.SetBinding(CurrentPluginsProperty, b);

            Binding b2 = new Binding();
            b2.Source = PluginContext.Current;
            b2.Path = new PropertyPath("ActivePlugin");
            b2.Mode = BindingMode.TwoWay;
            this.SetBinding(ActivePluginProperty, b2);

        }




        private void Current_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            //if (e.PropertyName == "Plugins")
            //{
            //    this.LoadedPlugins = new ObservableCollection<IPlugin>(Context.Current.Plugins);
            //    return;
            //}

            //if (e.PropertyName == "SelectedPlugin")
            //{
            //    this.LoadedPlugins = new ObservableCollection<IPlugin>(Context.Current.Plugins);
            //    this.ActivePlugin = Context.Current.SelectedPlugin;
            //    return;
            //}
        }

        private void AddPlugin(IPlugin plugin)
        {

           
        }


        #region Event Handlers


        private void DocumentViewLoaded(object sender, RoutedEventArgs e)
        {
        }

      

        #endregion

       

        //private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    if (ContentListBox.SelectedIndex > -1)
        //    {
        //        ListBoxItem listBoxItem = (ListBoxItem)ContentListBox.ItemContainerGenerator.ContainerFromIndex(ContentListBox.SelectedIndex);

        //        if (listBoxItem != null)
        //        {
        //            ContentPresenter contentHost = (ContentPresenter)listBoxItem.Template.FindName("PART_ContentHost", listBoxItem);
        //            DataTemplate dataTemplate = contentHost.ContentTemplate;

        //            _view = (IXamlDocumentView)dataTemplate.FindName("PART_DocumentView", contentHost);

        //            if (_view != null)
        //            {
        //                SelectedDocument = _view.XamlDocument;
        //                SelectedView = _view;
        //                SqlMiMInfo.Editor = SelectedView.TextEditor;
        //            }
        //        }
        //    }
        //}

        #region Public Methods


        #endregion
    }
}